import json

import pandas as pd, requests

sellBill = 'http://127.0.0.1:5000/user/receive_data'

gao = pd.read_excel(r"excel/modao.XLSX")

for index, row in gao.iterrows():  # 遍历数据类型DataFrame的每列数据
    params = row.to_dict()  # json无法序列化数据类型DataFrame，可通过内置方法.to_dict转换为字典
    params2 = dict()

    def modao():
        occur = params.get('记录的创建日期').strftime("%Y/%m/%d")
        params2['记录的创建日期'] = occur
        params2['交货单号'] = params.get('交货单号')
        params2['售达方名称'] = params.get('售达方名称')
        params2['销售订单项目短文本'] = params.get('销售订单项目短文本')
        params2['交货数量（吨）'] = (params.get('交货数量（吨）'))
        print(type(params2['交货数量（吨）']))
        params2['结算含税金额（元）'] = params.get('结算含税金额（元）')  # float
        params2['备注'] = params.get('备注')
        print(params2)

    modao()
    response = requests.post(sellBill, json=params2, headers={'Content-Type': 'application/json'})

    # break
    # print(response.status_code)
    if response.status_code == 200:
        print(f"成功发送第{index}行数据")
    else:
        print(f"发送第{index}行数据失败,状态代码{response.status_code}")

print("2")
